﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using zserialize;



public static class TestTool
{
	static string samplePath = "Assets/Sample";
	
	[MenuItem("Test_zserialize/CustomSerializeScript")]
	static void CustomSerializeScript()
	{
		SerializableFieldContainerHelper.serializeListener = new MySerializeListener();
		
		SerializeScriptTool.SerializeScript(SerializeScriptTool.backupDir);
	}
	

	[MenuItem("Test_zserialize/Print")]
	static void Print()
	{
		SerializableFieldContainerHelper.serializeListener = new MySerializeListener();

		{
			GameObject testPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(samplePath + "/Resources/test.prefab");
			GameObject testObj = GameObject.Instantiate(testPrefab);

			SerializableFieldContainerBehaviour b = testObj.GetComponent<SerializableFieldContainerBehaviour>();
			FieldDictionary fd = b.GetFieldDictionary();
			Debug.Log(fd);

			Object[] unityObjArr = fd.Get("UnityObjArr") as Object[];
			Debug.Log("test UnityObjArr field: " + unityObjArr.Length + "  " + unityObjArr[0] + "  " + unityObjArr[1] + "  " + unityObjArr[2] + "  " + unityObjArr[3]);


			List<object> unityObjList = fd.Get("UnityObjList") as List<object>;
			Debug.Log("test UnityObjList field: " + unityObjList.Count + "  " + unityObjList[0] + "  " + unityObjList[1] + "  " + unityObjList[2]);


			List<object> intList = fd.Get("intList") as List<object>;
			Debug.Log("test intList field: " + intList.Count + "  " + intList[0] + "  " + intList[1] + "  " + intList[2]);


			object[] customClassArr = fd.Get("testCustomClassArr") as object[];
			Debug.Log("test customClassArr field: " + customClassArr.Length + "  " + customClassArr[0].GetType() + "  " + customClassArr[0] + "  " + customClassArr[1]);

			GameObject.DestroyImmediate(testObj);
		}





		{
			SerializableFieldContainerScriptableObject testScriptObj = AssetDatabase.LoadAssetAtPath<SerializableFieldContainerScriptableObject>(samplePath + "/Resources/test3.asset");

			FieldDictionary fd = testScriptObj.GetFieldDictionary();
			Debug.Log(fd);

			Object[] unityObjArr = fd.Get("objArr") as Object[];
			Debug.Log("test objArr field: " + unityObjArr.Length + "  " + unityObjArr[0]);

			List<object> unityObjList = fd.Get("objList") as List<object>;
			Debug.Log("test objList field: " + unityObjList.Count + "  " + unityObjList[0]);
		}
	}
}